<?php

/**
 * Description of Model_transaction
 *
 * @author Meta Sanjaya
 */
class field_jenis_transaksi {

    static $orders = 0;
    static $quotes = 1;

}

class field_kode_transaksi {

    static $personal_bussiness_shopper = 'PBS';
    static $door_to_door = 'DTD';
    static $pickup = 'PKU';
    static $motorcycle = 'MTR';

}

class field_status_trasaksi {

    static $new = 0;
    static $review = 1;
    static $payed = 2;
    static $shipping = 3;
    static $success = 4;

}

class field_metoda_pembayaran {

    static $kartu_kredit = 1;
    static $tunai = 0;
    static $transfer_bca = 2;
    static $transfer_citibank = 3;

}

class field_master_transaksi {

    /**
     *
     * @var int
     */
    var $id;
    /**
     *
     * @var field_kode_transaksi
     */
    var $kode;
    /**
     *
     * @var int
     */
    var $urutan;
    /**
     *
     * @var string
     */
    var $tgl;
    /**
     *
     * @var field_jenis_transaksi
     */
    var $jenis;
    /**
     *
     * @var field_status_trasaksi
     */
    var $stat;
    /**
     *
     * @var int
     */
    var $sub_total = 0;
    /**
     *
     * @var int
     */
    var $service_charge = 0;
    /**
     *
     * @var int
     */
    var $rate = 0;
    /**
     *
     * @var field_metoda_pembayaran
     */
    var $metoda_pembayaran;
    /**
     *
     * @var int
     */
    var $total = 0;
    /**
     *
     * @var string
     */
    var $ip_address;
}

class info_order_personal_bussiness_shopper_world {

    var $nama_barang = array();
    var $url_item = array();
    var $jumlah = array();
    var $ukuran = array();
    var $warna = array();
    var $harga_item = array();
    var $berat_item = array();
    var $panjang = array();
    var $lebar = array();
    var $tinggi = array();
    var $photo_item = array();
    var $shipping_cost = array();

}

class info_billing {
    var $nama_lengkap;
    var $alamat;
    var $provinsi;
    var $telp;
    var $npwp;
}

class info_order_personal_bussiness_shopper_usa {

    var $nama_barang;
    var $url_item;
    var $jumlah;
    var $ukuran;
    var $warna;
    var $harga_item;
    var $berat_item;
    var $panjang;
    var $lebar;
    var $tinggi;
    var $photo_item;
    var $shipping_to_us;

}

class Model_transaction extends MY_Model {

    public function __construct() {
        parent::__construct();
    }

    /**
     *
     * @param mixed $tahun
     * @return field_master_transaksi
     */
    function get_all($tahun) {
        $return = array();
        $query = $this->db->query("select * from `" . DATABASE_PREFIX . $tahun . "`.`master_transaksi` order by id desc");

        foreach ($query->result() as $row) {
            $return[] = $row;
        }

        return $return;
    }

    function get_tahun($uri) {
        return array(
            array(
                'tahun' => '2011',
                'link' => site_url($uri . '/2011')
            )
        );
    }

    function get_urutan($kode_transaksi, $tahun) {
        switch ($kode_transaksi) {
            case field_kode_transaksi::$door_to_door:
                return $this->db->query("select * from `" . DATABASE_PREFIX . $tahun . "`.`detail_transaksi_order_dtd` union select * from `" . DATABASE_PREFIX . $tahun . "`.`detail_transaksi_order_dtds`")->num_rows();
                break;
            case field_kode_transaksi::$motorcycle:
                return $this->db->query("select * from `" . DATABASE_PREFIX . $tahun . "`.`detail_transaksi_order_mtr`")->num_rows();
                break;
            case field_kode_transaksi::$personal_bussiness_shopper:
                return $this->db->query("select * from `" . DATABASE_PREFIX . $tahun . "`.`detail_transaksi_order_pbu` union select * from `" . DATABASE_PREFIX . $tahun . "`.`detail_transaksi_order_pbw`")->num_rows();
                break;
            case field_kode_transaksi::$pickup:
                return $this->db->query("select * from `" . DATABASE_PREFIX . $tahun . "`.`detail_transaksi_order_pku`")->num_rows();
                break;
        }

        return -1;
    }

//    function get_key_field_kode_transaksi($val) {
//        $kode_transaksi = get_class_vars('field_kode_transaksi');
//
//        foreach ($kode_transaksi as $key => $value) {
//            if($value == $val) {
//                return $key;
//            }
//        }
//
//        return '';
//    }
// 
//    function get_id_field_kode_transaksi($text) {
//        $kode_transaksi = get_class_vars('field_kode_transaksi');
//
//        foreach ($kode_transaksi as $key => $value) {
//            if($text == strtolower(str_replace(' ', '_', $key))) {
//                return $value;
//            }
//        }
//
//        return -1;
//    }
}

?>
